package mySort;
//冒泡排序
public class BubbleSort {
    public void bubbleSort(int[] array) {
        for (int i = 0; i < array.length - 1; i++) { //表示趟数，i记得要小于长度-1
            boolean flg = false;
            for (int j = 0; i < array.length - 1 - i; j++) {
                if(array[j] > array[j+1]) {
                    swap(array,j,j+1);
                    flg = true;
                }
            }
            if (!flg) {
                break;
            }
        }
    }
    public void swap(int[] array, int i, int j) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}
